package api

import (
	"360-cinema/api-getaway/basic/config"
	"360-cinema/api-getaway/basic/handler/request"
	__ "360-cinema/api-getaway/basic/videoProto"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func CreateVideo(c *gin.Context) {

	var video request.CreateVideo
	err := c.ShouldBind(&video)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 0,
			"msg":  "参数错误",
		})
		return
	}
	r, err := config.VideoClient.CreateVideo(c, &__.CreateVideoReq{
		UserId:      int64(video.UserId),
		Title:       video.Title,
		Description: video.Description,
		CoverUrl:    video.CoverUrl,
		FileUrl:     video.FileUrl,
		Type:        video.Type,
		Address:     video.Address,
		Year:        video.Year,
		Play:        int64(video.Play),
		Like:        int64(video.Like),
		Collect:     int64(video.Collect),
		Comment:     int64(video.Comment),
		Status:      video.Status,
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	c.JSON(http.StatusOK, gin.H{
		"code": r.Code,
		"msg":  r.Msg,
		"data": r.Data,
	})
}
